package com.zs4sdk.entity;

import com.common.library.util.Helper;
import com.zs4sdk.common.Extra;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * function: 注册返回JSON类
 *
 * @ author: aXiBa
 */
public class AutoLoginJSONResultEntity extends LoginJSONResultEntity {

    /**
     * 构造方法
     */
    public AutoLoginJSONResultEntity() {

    }

    /**
     * 构造方法
     *
     * @param json
     */
    public AutoLoginJSONResultEntity(JSONObject json) {
        this.fromJSON(json);
    }

    /**
     * 构造方法
     *
     * @param jsonStr
     */
    public AutoLoginJSONResultEntity(String jsonStr) {
        try {
            this.fromJSON(new JSONObject(jsonStr));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public JSONObject toJSON() {
        JSONObject result = super.toJSON();
        try {
            result.put(COLUMN_USERID, this.userId);//
            result.put(COLUMN_USERCODE, this.usercode);//
            result.put(COLUMN_USERDESC, this.userDesc);//
            result.put(COLUMN_TOKEN, this.token);//
            result.put(COLUMN_NICKNAME, this.nickName);//
            result.put(COLUMN_AVATARURL, this.avatarurl);//
            result.put(COLUMN_LOGINKEY, this.loginKey);//
            result.put(COLUMN_LOGINTYPE, this.loginType);//
            result.put(COLUMN_VERIFY, this.verify);//
            result.put(COLUMN_ISPWD, this.ispwd);//
            result.put(COLUMN_MOBILE,this.mobile);//
          //  result.put(COLUMN_AGE, this.userAge);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return result;
    }
    public boolean isVerify() {
        if(verify.equals("1")) {
            return true;
        }
        else return false;
    }


    @Override
    public void fromJSON(JSONObject json) {
        super.fromJSON(json);
        if (Helper.isNotEmpty(json)) {
            this.userId = json.optString(COLUMN_USERID);
            this.usercode = json.optString(COLUMN_USERCODE);
            this.userDesc = json.optString(COLUMN_USERDESC);
            this.token = json.optString(COLUMN_TOKEN);
            this.nickName = json.optString(COLUMN_NICKNAME);
            this.avatarurl = json.optString(COLUMN_AVATARURL);
            this.loginKey = json.optString(COLUMN_LOGINKEY);
            this.loginType = json.optString(COLUMN_LOGINTYPE);
            this.verify = json.optString(COLUMN_VERIFY);
            this.ispwd = json.optString(COLUMN_ISPWD);
            this.mobile = json.optString(COLUMN_MOBILE);
            this.loginname = json.optString(COLUMN_LOGIN);
            if(Extra.isComplex()){//如果是繁体的情况下,是为没有电话号码的,直接变成loginname
                mobile = usercode;
            }
        }
    }
    public String getLoginname() {
        return nickName;
    }

    public String getMobile() {
        return mobile;
    }
}
